home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Misc / NewFile / Source / Help.m < prev    next >
Text File  |  1992-11-11  |  3KB  |  117 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. #import "Help.h"
  5. #import "Main.h"
  6. #import "Server.h"
  7. #import <appkit/NXBrowser.h>
  8. #import <appkit/NXBrowserCell.h>
  9. #import <appkit/ScrollView.h>
  10. #import <appkit/Text.h>
  11. #import <appkit/Panel.h>
  12. #import <appkit/Matrix.h>
  13. #import <appkit/Application.h>
  14. #import <sys/file.h>
  15. #import <sys/param.h>
  16. #import <libc.h>
  17.  
  18. @implementation Help
  19.  
  20. // Is interface loaded?
  21. // If more than one help instance, make this an instance var.
  22. int loaded=0;
  23.  
  24. /* Bring up the interface.*/
  25. - show:sender
  26. {
  27.     if (loaded==0)
  28.     {
  29.         [NXApp loadNibSection:"Help.nib" owner:self];
  30.     }
  31.     [panel makeKeyAndOrderFront:self];
  32.     [browser displayColumn:0];
  33.     return self;
  34. }
  35.  
  36.  
  37. /* Display the content of a file in the scrolling view.*/
  38. - loadFile:(char *)name
  39. {
  40.     int    fd;
  41.     NXStream *st;
  42.     
  43.     fd = open(name, O_RDONLY, 0);
  44.     if (fd >= 0)
  45.     {
  46.         if ((st = NXOpenFile(fd, NX_READONLY)) != 0)
  47.         {
  48.             [text readRichText:st];
  49.             [text sizeToFit];
  50.             // Set the `cursor' to the start of the text.
  51.             [text setSel:0:0];
  52.             // Adjust the scroll position so that start of text is visible.
  53.             [text scrollSelToVisible];
  54.             NXClose(st);
  55.         }
  56.         close(fd);
  57.     }
  58.     return self;
  59. }
  60.  
  61. /*
  62. This message is called by the entries in the `sections' section to display the appropriate help file.
  63. */
  64. - helpme:sender
  65. {
  66.     char title[100], name[MAXPATHLEN];
  67.     // The name of the help file is the same as the title of the section.
  68.     [sender getPath:title toColumn:1];
  69.     sprintf(name, "%s/Help%s", [appDelegate appdir], title);
  70.     [self loadFile:name];
  71.     return self;
  72. }
  73.  
  74. // Respond to the browser's query about whether the data has been loaded. 
  75. - (BOOL)browser:sender columnIsValid:(int)column
  76. {
  77.     return loaded!=0;
  78. }
  79.  
  80. // Add a help section to the list. 
  81. - addTopic:(char *)title at:(int)pos in:matrix for:browser
  82. {
  83.     id cell;
  84.     [matrix insertRowAt:pos];
  85.     cell = [matrix cellAt:pos:0];
  86.     [cell setStringValue:title];
  87.     [cell setLoaded:YES];
  88.     [cell setLeaf:YES];
  89.     return self;
  90. }
  91.  
  92. // Fill the list of help sections.
  93. - (int)browser:sender fillMatrix:matrix inColumn:(int)column
  94. {
  95.     [self addTopic:"What is NewFile" at:0 in:matrix for:sender];
  96.     [self addTopic:"General use" at:1 in:matrix for:sender];
  97.     [self addTopic:"Current directory" at:2 in:matrix for:sender];
  98.     [self addTopic:"Defining file types" at:3 in:matrix for:sender];
  99.     [self addTopic:"Updating Services" at:4 in:matrix for:sender];
  100.     [self addTopic:"Command keys" at:5 in:matrix for:sender];
  101.     [self addTopic:"Things to do" at:6 in:matrix for:sender];
  102.     [self addTopic:"Info" at:7 in:matrix for:sender];
  103.     loaded++;
  104.     // Return the number of sections.
  105.     return 8;
  106. }
  107.  
  108. // Intercept the scrolling view's initialization to get its doc view.
  109. - setScrollingview:anObject
  110. {
  111.     scrollingview = anObject;
  112.     text = [scrollingview docView];
  113.     return self;
  114. }
  115.  
  116. @end
  117.